package com.ruoyi.web.controller.gcgl;

import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gcgl.domain.GcSupply;
import com.ruoyi.gcgl.service.IGcSupplyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.ReturnUUID;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商管理Controller
 * 
 * @author ruoyi
 * @date 2022-11-27
 */
@Controller
@RequestMapping("/gcgl/supply4bzjdw")
public class GcSupply4bzjdwController extends BaseController
{
    private String prefix = "gcgl/supply";

    @Autowired
    private IGcSupplyService gcSupplyService;

    @RequiresPermissions("gcgl:supply4bzjdw:view")
    @GetMapping()
    public String supply()
    {
        return prefix + "/supply4bzjdw";
    }

    /**
     * 查询供应商管理列表
     */
    @RequiresPermissions("gcgl:supply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GcSupply gcSupply)
    {
        startPage();
        gcSupply.setDeleteFlag(1);
        gcSupply.setType(6);
        List<GcSupply> list = gcSupplyService.selectGcSupplyList(gcSupply);
        return getDataTable(list);
    }

    /**
     * 导出供应商管理列表
     */
    @RequiresPermissions("gcgl:supply:export")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GcSupply gcSupply)
    {
    	gcSupply.setDeleteFlag(1);
    	gcSupply.setType(6);
        List<GcSupply> list = gcSupplyService.selectGcSupplyList(gcSupply);
        ExcelUtil<GcSupply> util = new ExcelUtil<GcSupply>(GcSupply.class);
        return util.exportExcel(list, "供应商管理数据");
    }

    /**
     * 新增供应商管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add4bzjdw";
    }

    /**
     * 新增保存供应商管理
     */
    @RequiresPermissions("gcgl:supply:add")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GcSupply gcSupply)
    {
    	gcSupply.setType(6);
    	gcSupply.setOrderNo(ReturnUUID.getOrderNo("SU"));
    	gcSupply.setName(gcSupply.getCkdw());
    	gcSupply.setDeleteFlag(1);
    	gcSupply.setCreateAt(new Date());
    	gcSupply.setUpdateAt(new Date());
    	gcSupply.setCreateUser(getLoginName());
    	gcSupply.setUpdateUser(getLoginName());
        return toAjax(gcSupplyService.insertGcSupply(gcSupply));
    }

    /**
     * 修改供应商管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GcSupply gcSupply = gcSupplyService.selectGcSupplyById(id);
        mmap.put("gcSupply", gcSupply);
        return prefix + "/edit4bzjdw";
    }

    /**
     * 修改保存供应商管理
     */
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GcSupply gcSupply)
    {
    	gcSupply.setName(gcSupply.getCkdw());
        return toAjax(gcSupplyService.updateGcSupply(gcSupply));
    }

    /**
     * 删除供应商管理
     */
    @RequiresPermissions("gcgl:supply:remove")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gcSupplyService.deleteGcSupplyByIds(ids));
    }
}
